<!--# layout("/templates/layout/layout_main.html",{"title":"编辑权限","nameSpace":"permission_admin","breadcrumbs":[{"name":"权限管理","url":"permission/list"},{"name":"权限编辑"}]}){ #-->
<!--# var permission = obj.data.permission ; #-->
<link rel="stylesheet" href="${base}/assets/biz-logic/js/ztree/css/zTreeStyle.css"/>
<div class="container-fluid">
	<div class="row">
		<div class="col-sm-8 col-sm-offset-2 ">
			<div  class="hr-20"></div>
			<form id="edit-form" class="form-horizontal" role="form" method="post">
				<input type="hidden" id="form-field-id" name="id" value="${obj.data.permission.id!}"/>
				<input type="hidden" id="form-field-level" name="level" value="${obj.data.permission.level!}"/>
				<div class="form-group">
					<label for="form-field-name" class="col-sm-2 control-label no-padding-right">权限名称</label>
					<div class="col-sm-5">
						<input type="text" class="form-control" id="form-field-name" name="name" ${obj.data.permission.installed!false ? 'readonly="readOnly"' : ''} data-type='required'  data-error='请输入权限名称'  placeholder="请输入权限名称" value="${obj.data.permission.name!}" />
					</div>
				</div>
				
				<div class="form-group">
					<label for="form-field-desc" class="col-sm-2 control-label no-padding-right">权限描述</label>
					<div class="col-sm-5">
						<input type="text" class="form-control" id="form-field-desc" name="description" data-type='required' data-error='请输入权限描述' placeholder="请输入权限描述" value="${obj.data.permission.description!}" />
					</div>
				</div>
				<div class="form-group">
					<label for="form-field-url" class="col-sm-2 control-label no-padding-right">权限URl</label>
					<div class="col-sm-5">
						<input type="text"  class="form-control" name="url" id="form-field-url" data-type='' data-error='请输入权限URL'  placeholder="请输入权限URL" value="${obj.data.permission.url!}" />
					</div>
				</div>
				
				<div class="form-group">
					<label for="form-field-needPermission" class="col-sm-2 control-label no-padding-right">前置权限</label>
					<div class="col-sm-5">
						<div class="input-group">
							<input type="text"  class="form-control" name="needPermission" id="form-field-needPermission" readonly="readonly"  data-error='请选择前置权限'  placeholder="选择前置权限" value="${obj.data.permission.needPermission!}" />
							<span class="input-group-addon search-btn" style="cursor: pointer;" id="btn-chose"> 选择 
								<i class="ace-icon glyphicon glyphicon-pencil align-top icon-on-right"></i>
							</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="form-field-icon" class="col-sm-2 control-label no-padding-right">权限图标</label>
					<div class="col-sm-5">
						<input type="text"  class="form-control" name="icon" id="form-field-icon" data-type='' data-error='设置的权限图标'  placeholder="设置权限图标" value="${obj.data.permission.icon!}" />
					</div>
					<div class="col-sm-5" style="line-height:35px;">
						<a href="http://fontawesome.dashgame.com/" target="_blank">点此处查找图标</a>
					</div>
				</div>
				<div class="form-group">
					<label for="form-field-ismenu" class="col-sm-2 control-label no-padding-right">是否菜单</label>
					<div class="col-sm-5">
						<label style="padding:5px;">
						<input name="menu" class="ace ace-switch ace-switch-5" 
						type="checkbox" value="true" ${permission == null || (permission != null && permission.isMenu)  ? "checked":""} /> 
						<span class="lbl"></span>
						</label>
					</div>
				</div>
				<div class="" id="dialogs">
					<div id="menuDialog" style="padding:10px;padding-left:15%;"  class="hidden">
						<ul id="menuTree" class="ztree"></ul>
					</div>
				</div>
				<!-- <div class="form-group">
					<label for="form-field-avatar" class="col-sm-2 control-label no-padding-right">用户头像</label>
					<div class="col-sm-3">
						<input type="file" name="avatar" accept="image/*" />
					</div>
				</div> -->
								
				
				<hr class="hr-30" />
				<div class="col-sm-12 center" >
					<button class="btn btn-sm" data-dismiss="modal"  type="button"  onclick="javascript:history.back();">
							<i class="ace-icon fa fa-times"></i>
							取 消
						</button>
	
						<button class="btn btn-sm btn-primary" type="button" onclick="editSave(this)">
							<i class="ace-icon fa fa-check"></i>
							保 存
						</button>
				</div>
			</form>
		</div>
	</div>
</div>
<!--# } #-->
<script src="${base}/assets/biz-logic/js/ztree/jquery.ztree.all.min.js"></script>
<script type="text/javascript">

$(function(){
	var menuTreeSetting = {
			async: {
				enable: true,
				url:getRootPath() + "/permission/getTree",
				autoParam:["id", "name"],
				type:'post'
			},
			check: {
				enable: false,
				autoCheckTrigger: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "p", "Y": "ps" },
				nocheckInherit: true,
				chkDisabledInherit: true
			},
			callback:{
				onNodeCreated:function(e, treeid, treeNode){
				},
				onAsyncSuccess:function(event, treeId, treeNode, msg){
					var treeObj = $.fn.zTree.getZTreeObj("menuTree");
					treeObj.expandAll(true);
				},
				onClick: function(event, treeId, treeNode){
					$('#edit-form input[name=needPermission]').val(treeNode.value);
					$('#edit-form input[name=level]').val(treeNode.level + 1);
					layer.closeAll();
				}
			}
	};
	function toSelect(){
		var ztree = $.fn.zTree.init($("#menuTree"), menuTreeSetting);
		layer.open({
		  type: 1,
		  title:'选择前置权限',
		  skin: 'layui-layer-rim', //加上边框
		  area: ['320px', '340px'], //宽高
		  content: $('#menuDialog')
		});
		$("#menuDialog").removeClass("hidden");
	}
	$('#btn-chose').on("click", toSelect);
})

function editSave(btn){
	if ($('#edit-form').find('input,select').validation()) {//验证表单
		var myform = $('#edit-form') ;
		$.ajax({
			type:'post',
			url:getRootPath() + '/permission/${obj.data.permission == null?"add.do":"update.do"}',
			data:$('#edit-form').serialize(),
			dataType:'json',
			success:function(result) {
			if (result.operationState == 'SUCCESS') {
				location.href = getRootPath() + "/permission/list";
			} else {
				layer.msg(result.data.reason);
			}
		}});
	}
}
</script>

  